//
//  SNNickNameView.m
//  project
//
//  Created by 黄建华 on 2020/12/6.
//  Copyright © 2020 黄建华. All rights reserved.
//

#import "SNNickNameView.h"

@implementation SNNickNameView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        [self createUi];
    }
    return self;
}

- (void)createUi
{
    self.layer.backgroundColor = [UIColor colorWithRed:240/255.0 green:240/255.0 blue:246/255.0 alpha:1.0].CGColor;
    self.layer.masksToBounds = YES;
    
    UIView *view = [[UIView alloc] initWithFrame:SNFRAME(0, 0, screenWidth, 44)];
    view.backgroundColor = [UIColor whiteColor];
    [self addSubview:view];
    
    UILabel *titleLabel = [UILabel simpleWithRect:SNFRAME(0, 0, screenWidth, 44) withAlignment:NSTextAlignmentCenter withFontSize:16 withText:SN_Text(@"用户昵称") withTextColor:UIColorHEX(0x161616)];
    titleLabel.font = SNFONTMEDIUM(16);
    [self addSubview:titleLabel];
    
    
    UIView *view1 = [[UIView alloc] initWithFrame:SNFRAME(20, titleLabel.bottom +33, screenWidth-50, 50)];
    view1.backgroundColor = [UIColor whiteColor];
    view1.layer.cornerRadius = 6;
    [self addSubview:view1];
    
    UILabel *infoL = [UILabel simpleWithRect:SNFRAME(10, view1.bottom +14, screenWidth-20, 20) withAlignment:NSTextAlignmentCenter withFontSize:13 withText:SN_Text(@"不超过18个字符，只支持中英文与数字。") withTextColor:UIColorHEX(0x96969F)];
    infoL.adjustsFontSizeToFitWidth = YES;
    [self addSubview:infoL];
    
    _textFiled = [[UITextField alloc] initWithFrame:SNFRAME(35, titleLabel.bottom +33, screenWidth-65, 50)];
    _textFiled.placeholder = SN_Text(@"请输入您的昵称...");
    if (SN_USER.nickName.length > 0) {
        _textFiled.text = SN_USER.nickName;
    }
    _textFiled.delegate = self;
    _textFiled.font = SNFONTREGULAR(17);
    _textFiled.textColor = UIColorHEX(0x161616);
    
    [self addSubview:_textFiled];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:SNFRAME(screenWidth/2-90, 44 +287, 180, 36)];
    [btn setTitle:SN_Text(@"确定") forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor = UIColorHEX(0xFF7A00);
    btn.layer.cornerRadius = 6;
    [self addSubview:btn];
    
    [btn addTouchUpTarget:self action:@selector(btnTouchInWith)];
    
}

- (void)btnTouchInWith
{
    if (_backBlock) {
        _backBlock(_textFiled.text);
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (_backBlock) {
        _backBlock(_textFiled.text);
    }
}

@end
